package com.zhai.application.cotroller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.zhai.application.dal.CommonFlowRuleConfigItemMapper;
import com.zhai.application.dal.TaskDispatchSiteMapper;
import com.zhai.application.entity.InfraFlowRuleItemEntity;
import com.zhai.application.entity.TaskDispatchSite;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dispatch")
public class TmsDispatchSiteController {

    @Resource
    private TaskDispatchSiteMapper taskDispatchSiteMapper;

    @PostMapping("/saveSite")
    public JSONObject saveSite(){
        JSONObject result = new JSONObject();
        TaskDispatchSite record = new TaskDispatchSite();
        record.setActivateStatus("2");
        record.setDispatchId(1706755931347770L);
        record.setSiteId(55282925436625L);
        record.setSiteLat(new BigDecimal(23));
        record.setSiteLng(new BigDecimal(26));
        record.setArriveCoordinate("南京");
        record.setLeaveCoordinate("北京");
        record.setConsignerSiteName("潍坊寒亭站");
        record.setSerialNum(99);
        record.setLeaveLocation("88.0123");
        record.setArriveLocation("99.2345");
        record.setStatus("1");
        record.setArriveLeaveFlag("2");
        record.setArriveDate(new Date());
        record.setLeaveDate(DateUtil.beginOfWeek(new Date()));
        record.setCreateDate(new Date());
        record.setUpdateDate(new Date());
        record.setCreateUserId("8189724944058482688");
        record.setUpdateUserId("8189724944058482688");
        record.setRemark("测试数据");
        record.setId(IdUtil.getSnowflakeNextId());
        record.setDelFlag("1");

        taskDispatchSiteMapper.insert(record);

        result.put("success",true);
        return result;
    }

    @PostMapping("/queryAllSite")
    public JSONObject queryAllSite(){
        JSONObject result = new JSONObject();

        List<TaskDispatchSite> taskDispatchSites = taskDispatchSiteMapper.listTaskDispatch();

        result.put("success",true);
        result.put("data",taskDispatchSites);
        return result;
    }
}
